<?php
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="/<?php echo(AdminDir);?>/style/jquery.min.js"></script>
    <link rel="shortcut icon" href="../<?php echo(AdminDir);?>/img/ico.ico" >
    <title>UCMS魔改版<?php echo(version);?>安装</title>
    <script type="text/javascript">cmsversion='<?php echo(version);?>';</script>
    <style>
        body{ color:#4791d0; font-size:12px; font-family: "Microsoft YaHei",STHeiti,"Hiragino Sans GB","WenQuanYi Micro Hei","Heiti SC", NSimSun,SimSun,Arial, Helvetica, sans-serif; }
        table{ border-collapse:collapse; }
        td{ padding:5px 10px; }
        input{ font-size: 12px; line-height: 20px; height: 22px; padding-left:5px; font-weight:bold; }
        label{ line-height: 12px; }
        label input{ height: 12px; }
        i{ font-size:12px; font-style: normal; color:#ccc; margin-left:10px; }
        .main{ width:666px; margin:0 auto; margin-top:80px; padding:0px; }
        .title{ font-size:18px; font-weight:bold; padding:8px 0 8px 10px; background: #1c86d1; color:#fff; }
        .title1{ font-size:14px; font-weight:bold; }
        .info{ border-left:1px solid #eee; border-right:1px solid #eee; border-bottom:1px solid #eee; padding:20px; margin: 0 auto; }
        .detail{ padding-left:20px; color:#000; font-size:12px; padding-bottom:10px; }
        .detail li{ border-bottom:1px #eee dotted; margin-top:5px; padding-bottom:5px; width:500px; }
        .detail li em{ float:right; margin-right:50px; font-style: normal; }
        .tip{ margin-top:5px; border:1px solid #eee; padding:10px; width:400px; margin-left:30px; color:#ff0000; font-size:12px; line-height:20px; }
        .nextstep{ display:block; margin:20px 30px 0 200px; height:25px; width:90px; font-size:14px; }
        #databaseinfo{padding:10px;}
        .mysqltd{display:none;}
        .sqlitetd{display:none;}
        a{color:#0000FF;}
        .uuulogin p{}
    </style>
</head>
<body>
<div class="main">
    <?php if($step==0) {?>
        <div class="title">安装向导--环境检查</div>
        <div class="info">
            <form method=post action="?step=1">
                <div class="detail">
                    <li>PHP版本 <em><?php echo(PHP_VERSION);?></em></li>
                    <li>pdo_mysql 组件<em><?php ext_exist('pdo_mysql');?></em></li>
                    <?php
                    if(!ext_exist('pdo_mysql',1)) {
                        ?>
                        <li>MYSQL组件<em><?php ext_exist('mysql');?></em></li>
                        <?php
                    }
                    ?>
                    <li>pdo_sqlite 组件<em><?php ext_exist('pdo_sqlite');?></em></li>
                    <li>JSON <em><?php ext_exist('json');?></em></li>
                    <li>缓存目录(cache)读写权限 <em><?php echo($cachedirtips);?></em></li>
                    <li>上传目录(uploadfile)读写权限 <em><?php echo($uploadfiledirtips);?></em></li>
                    <li>Sqlite数据库目录(inc)读写权限 <em><?php echo($incdirtips);?></em></li>
                    <?php
                    if(strlen($info)>0) {
                        echo('<div class="tip">'.$info.'</div>');
                    }
                    ?>

                    <input type="button" onclick="javascript:window.location.href='<?=R("install/step1")?>';" value="<?php if($disableinstall==1){echo('无法安装');}else{echo('下一步');}?>" class="nextstep" <?php if($disableinstall==1){echo(' disabled');}?>><br>
                    <a href="http://uuu.la/help/download.html" target="_blank">查看最新版本UCMS</a>
                </div>
            </form>
        </div>
    <?php }?>

    <?php if($step==1) {?>
        <div class="title">安装向导--配置</div>
        <div class="info">
            <form method=post action="/install/step2" onsubmit="return installcheck()">
                <div class="detail ">

                    <div class="title1">数据库连接信息</div>
                    <table width=600>
                        <tr>
                            <td align="left" width=120>数据库类型 : </td>
                            <td>
                                <label><input type="radio" name="database" id="mysqlradio" value="<?php echo($defaultmysql);?>" <?php if($mysqldatabase==false) {echo(' disabled');}else{echo(' checked');}?>>MySQL</label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label><input type="radio" name="database" id="sqliteradio" value="sqlitepdo"<?php if($sqlitedatabase==false) {echo(' disabled');}if($sqlitedatabase==true && $mysqldatabase==false) {echo('checked');}?>>SQLite</label>
                                <i><a href="http://uuu.la/help/database.html" target="_blank">数据库选择说明</a></i>
                            </td>
                        </tr>
                        <tr class="mysqltd">
                            <td align="left" width=120>MySQL主机地址 : </td>
                            <td>
                                <input type="text" name="mysql_host" id="mysql_host" size="40" value="127.0.0.1"><i>如:localhost:3306</i>
                            </td>
                        </tr>
                        <tr class="mysqltd">
                            <td align="left" width=120>数据库名称 : </td>
                            <td>
                                <input type="text" name="mysql_dbname" id="mysql_dbname" size=40>
                            </td>
                        </tr>
                        <tr class="mysqltd">
                            <td align="left" width=120>数据库用户名 : </td>
                            <td>
                                <input type="text" name="mysql_user" id="mysql_user" size=40>
                            </td>
                        </tr>
                        <tr class="mysqltd">
                            <td align="left" width=120>数据库用户密码 : </td>
                            <td>
                                <input type="password" name="mysql_password" id="mysql_password" size=40>
                                <i id="databasetest" style="display:none;cursor:pointer">连接测试</i>
                                <script>
                                    if (typeof jQuery == 'undefined') {
                                        alert('jQuery载入失败,请先将后台目录重命名为ucms');
                                    }
                                    $(function(){
                                        $('#mysql_password').change(function(){
                                            database_test();
                                        });
                                        $('#mysql_user').change(function(){
                                            database_test();
                                        });
                                        $('#databasetest').click(function(){
                                            database_test();
                                        });
                                    });
                                    function database_test(){
                                        host=$('#mysql_host').val();
                                        user=$('#mysql_user').val();
                                        psd=$('#mysql_password').val();
                                        linkkind='<?php echo($defaultmysql);?>';
                                        if (host.length>3 && user.length>0 && psd.length>0)
                                        {
                                            $('#databasetest').css('color','#ccc');
                                            $('#databasetest').text('连接测试中');
                                            $('#databasetest').show();
                                            $.post("?databasetest=1",
                                                {
                                                    host:host,
                                                    user:user,
                                                    psd:psd,
                                                    linkkind:linkkind
                                                },
                                                function(data,status){
                                                    if (data=='连接成功')
                                                    {
                                                        $('#databasetest').css('color','#ccc');
                                                    }else{
                                                        $('#databasetest').css('color','#ff0000');
                                                    }
                                                    $('#databasetest').text(data);
                                                    $('#databasetest').show();
                                                });
                                        }
                                    }
                                </script>
                            </td>
                        </tr>
                        <tr class="sqlitetd">
                            <td align="left" width=120>SQLite数据库文件名 : </td>
                            <td>
                                <input type="text" name="sqlite_dbfile" id="sqlite_dbfile" size=40 value="<?php echo($sqlite_dbname);?>" readonly>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width=120>数据库表名前缀 : </td>
                            <td>
                                <input type="text" name="tableex" id="tableex" size=40 value="ucms_"><i>避免与其他程序重复</i>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width=120></td>
                            <td></td>
                        </tr>
                    </table>
                    <div class="title1">网站配置</div>
                    <table width=550>
                        <tr>
                            <td align="left" width=120 valign=top>网站域名 : </td>
                            <td valign=top>
                                <?php
                                $otherdomain='';
                                if(substr(serverName(),0,4)=='www.') {
                                    $otherdomain=';'.substr(serverName(),4,strlen(serverName()));
                                }else {
                                    if(substr_count(serverName(),".")==1) {
                                        $otherdomain=';www.'.serverName();
                                    }else {
                                        if(substr_count(serverName(),".")==2 && substr(serverName(),-6)=='com.cn') {
                                            $otherdomain=';www.'.serverName();
                                        }
                                    }
                                }
                                ?>
                                <input type="text" name="systemdomain" id="systemdomain" size=40 value=""><i>多个用;分隔</i><br><i>不限制域名访问则无需填写。绑定域名后只允许通过该域名访问。</i>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width=120>伪静态 : </td>
                            <td>
                                <label id="urlrewriteradiotips"><input type="radio" id="urlrewriteradio" name="urlrewrite" value="1"<?php if($installdir!="/") {echo(' disabled');}?>>启用<?php if($installdir!="/") {echo('(未开启伪静态)');}?></label>
                                <label><input type="radio" id="urlrewriteradiono" name="urlrewrite" value="0" checked>不启用</label>
                                <i>
                                    <?php
                                    if(stripos(@$_SERVER['SERVER_SOFTWARE'],'ginx')>0) {
                                        echo('<a href="http://uuu.la/help/nginxrewrite.html" target="_blank">NGINX伪静态配置说明</a>');
                                        echo('<script type="text/javascript">alert("NGINX服务器请先配置伪静态规则,并启用伪静态,否则前台无法访问,具体配置请查看配置说明");</script>');
                                    }elseif(stripos(@$_SERVER['SERVER_SOFTWARE'],'pache')>0){
                                        echo('<a href="http://uuu.la/help/apacherewrite.html" target="_blank">APACHE伪静态配置说明</a>');
                                    }elseif(stripos(@$_SERVER['SERVER_SOFTWARE'],'IIS')>0){
                                        echo('<a href="http://uuu.la/help/iisrewrite.html" target="_blank">IIS伪静态配置说明</a>');
                                    }else {
                                        echo('<a href="http://uuu.la/help/rewrite.html" target="_blank">配置说明</a>');
                                    }
                                    ?>

                                </i>
                                <?php if($installdir=="'/'") {
                                    ?>
                                    <script>
                                        $(window).load(function (){
                                            setTimeout("setrewrite();",1000)
                                        });
                                        function setrewrite(){
                                            rewriteurl=document.getElementById("rewriterestiframe").contentWindow.location.href;
                                            if (rewriteurl.indexOf("install")>0)
                                            {
                                                $('#urlrewriteradiotips').append('(配置成功)');
                                                $('#urlrewriteradio').attr('checked','true');
                                                $("#urlrewriteradio").unbind("click");
                                            }else{
                                                $('#urlrewriteradio').click(function(){
                                                    alert('系统检测到伪静态尚未配置成功.\r\n请在配置成功后开启. 否则会造成网站前台无法访问.\r\n安装后也可修改inc/config.php文件选择是否启用伪静态');
                                                });
                                            }
                                        }
                                    </script>
                                    <iframe id="rewriterestiframe" src="<?php echo($rewritetesturi);?>" style="display:none"></iframe>
                                    <?php
                                }
                                ?>
                            </td>
                        </tr>
                    </table>

                    <div class="title1">管理员帐户信息</div>

                    <table width=550>
                        <tr>
                            <td align="left" width=120>用户名 : </td>
                            <td>
                                <input type="text" name="uuuadminname" id="uuuadminname" size=25 value="admin" style="float:left">
                                <div id="uuulogin" style="float:left;margin-left:10px;margin-top:-2px;">
                                    <p class="ucms3login qqlogin" rel="qq"></p>
                                </div>
                                <i>绑定QQ登录</i>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width=120>密码 : </td>
                            <td>
                                <input type="password" name="uuuadminpassword" id="uuuadminpassword" size=40>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width=120>重复密码 : </td>
                            <td>
                                <input type="password" name="uuuadminpassword2" id="uuuadminpassword2" size=40>
                            </td>
                        </tr>
                    </table>
                    <script type="text/javascript">
                        $('#systemdomain').change(function(){
                            systemdomain_check();
                        });
                        <?php
                        if($mysqldatabase==true) {
                            echo("$('.mysqltd').show();");
                        }elseif($sqlitedatabase==true) {
                            echo("$('.sqlitetd').show();");
                        }else {
                            echo("alert('抱歉,您的空间不支持mysql或sqlite数据库,不能安装本程序');");
                        }
                        ?>
                        $('#mysqlradio').click(function(){
                            if ($('#mysqlradio').prop('checked'))
                            {
                                $('.mysqltd').show();
                                $('.sqlitetd').hide();
                            }else{
                                $('.mysqltd').hide();
                            }
                        });
                        $('#sqliteradio').click(function(){
                            if ($('#sqliteradio').prop('checked'))
                            {
                                $('.sqlitetd').show();
                                $('.mysqltd').hide();
                            }else{
                                $('.sqlitetd').hide();
                            }
                        });
                        function installcheck()
                        {
                            <?php if($mysqldatabase==true) {}elseif($sqlitedatabase==true) {}else {echo("alert('抱歉,您的空间不支持mysql或sqlite数据库,不能安装本程序');");}?>
                            if ($('#mysqlradio').prop('checked'))
                            {
                                if ($('#mysql_host').val()=='')
                                {
                                    alert('请填写MySQL主机地址');$('#mysql_host').focus();return false;
                                }
                                if ($('#mysql_dbname').val()=='')
                                {
                                    alert('请填写数据库名称');$('#mysql_dbname').focus();return false;
                                }
                                if ($('#mysql_user').val()=='')
                                {
                                    alert('请填写数据库用户名');$('#mysql_user').focus();return false;
                                }
                            }
                            if (/^[a-zA-Z][0-9a-zA-Z_]{0,}$/.test($('#tableex').val())==false)
                            {
                                alert('表名前缀请使用英文字母为前缀');
                                return false;
                            }
                            if (systemdomain_check()==false)
                            {
                                return false;
                            }
                            if ($('#uuuadminname').val()=='')
                            {
                                alert('请填写管理员用户名');$('#uuuadminname').focus();return false;
                            }
                            if (!isNaN($('#uuuadminname').val()))
                            {
                                alert('用户名不能为数字');$('#uuuadminname').focus();return false;
                            }

                            if ($('#uuuadminpassword').val()=='')
                            {
                                alert('请填写管理员密码');$('#uuuadminpassword').focus();return false;
                            }
                            if ($('#uuuadminpassword').val()!=$('#uuuadminpassword2').val())
                            {
                                alert('管理员密码与重复密码不一致');$('#uuuadminpassword').focus();return false;
                            }
                            return true;
                        }
                        function systemdomain_check(){
                            var inputdomain=$('#systemdomain').val();
                            if (inputdomain.indexOf('http://')>-1)
                            {
                                alert("域名填写有误,无需添加http://");
                                return false;
                            }
                            if (inputdomain.indexOf('/')>-1)
                            {
                                alert("域名填写有误");
                                return false;
                            }
                            if (inputdomain.indexOf(':')>-1)
                            {
                                alert("域名填写有误,无需填写端口");
                                return false;
                            }
                            return true;
                        }
                    </script>
                    <input type="submit" value="安装" class="nextstep">

                </div>
        </div>
        </form>
    <?php }?>
</div>
</body>
</html>
